package com.ruoyi.project.gzbook.recommand.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.gzbook.recommand.domain.DgWeekRecommand;
import com.ruoyi.project.gzbook.recommand.service.IDgWeekRecommandService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 每周推荐Controller
 * 
 * @author mhg
 * @date 2021-10-06
 */
@Controller
@RequestMapping("/gzbook/recommand")
public class DgWeekRecommandController extends BaseController
{
    private String prefix = "gzbook/recommand";

    @Autowired
    private IDgWeekRecommandService dgWeekRecommandService;

    @RequiresPermissions("gzbook:recommand:view")
    @GetMapping()
    public String recommand()
    {
        return prefix + "/recommand";
    }

    /**
     * 查询每周推荐列表
     */
    @RequiresPermissions("gzbook:recommand:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DgWeekRecommand dgWeekRecommand)
    {
        startPage();
        List<DgWeekRecommand> list = dgWeekRecommandService.selectDgWeekRecommandList(dgWeekRecommand);
        return getDataTable(list);
    }

    /**
     * 导出每周推荐列表
     */
    @RequiresPermissions("gzbook:recommand:export")
    @Log(title = "每周推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DgWeekRecommand dgWeekRecommand)
    {
        List<DgWeekRecommand> list = dgWeekRecommandService.selectDgWeekRecommandList(dgWeekRecommand);
        ExcelUtil<DgWeekRecommand> util = new ExcelUtil<DgWeekRecommand>(DgWeekRecommand.class);
        return util.exportExcel(list, "每周推荐数据");
    }

    /**
     * 新增每周推荐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存每周推荐
     */
    @RequiresPermissions("gzbook:recommand:add")
    @Log(title = "每周推荐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DgWeekRecommand dgWeekRecommand)
    {
        return toAjax(dgWeekRecommandService.insertDgWeekRecommand(dgWeekRecommand));
    }

    /**
     * 修改每周推荐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DgWeekRecommand dgWeekRecommand = dgWeekRecommandService.selectDgWeekRecommandById(id);
        mmap.put("dgWeekRecommand", dgWeekRecommand);
        return prefix + "/edit";
    }

    /**
     * 修改保存每周推荐
     */
    @RequiresPermissions("gzbook:recommand:edit")
    @Log(title = "每周推荐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DgWeekRecommand dgWeekRecommand)
    {
        return toAjax(dgWeekRecommandService.updateDgWeekRecommand(dgWeekRecommand));
    }

    /**
     * 删除每周推荐
     */
    @RequiresPermissions("gzbook:recommand:remove")
    @Log(title = "每周推荐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dgWeekRecommandService.deleteDgWeekRecommandByIds(ids));
    }
}
